//
//  LKVisitorView.swift
//  LKweibo
//
//  Created by mac on 16/4/4.
//  Copyright © 2016年 什么人玩什么鸟. All rights reserved.
//

import UIKit

class LKVisitorView: UIView {
    
    //向外部提供一个方法,改变每个视图显示的文字和图片
    func setupInfoUI(title: String, imgName: String?) {
        textLabel.text = title

        guard let imgName = imgName else{
            
            //旋转动画
            stratState()
            return
        }
        centerImg.image = UIImage(named: imgName)
        yuanQuan.hidden = true
    }
    
    private func stratState(){
        
    }

    //代码方式加载视图
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    //xib方式加载视图
    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented") 此句要删掉
        super.init(coder: aDecoder)
    }
    
// MARK: - 懒加载
    //圆
    private lazy var yuanQuan: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    //圆心图
    private lazy var centerImg: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    //遮罩效果
    private lazy var maakView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    //文字
    private lazy var textLabel: UILabel = {
       let label = UILabel()
        label.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        label.textColor = UIColor.darkGrayColor()
        label.font = UIFont.systemFontOfSize(14)
        label.numberOfLines = 0
        label.textAlignment = NSTextAlignment.Center
        
        return label
        
    }()
    //注册按钮
    private lazy var registerButton: UIButton = UIButton(bgImgName: "common_button_white_disable", titleName: "注册")
    
    //登录按钮
    private lazy var loginButton: UIButton = UIButton(bgImgName: "common_button_white_disable", titleName: "登录")
    
  

}

//创建视图UI
extension LKVisitorView{
    private func setupUI(){
        
        backgroundColor = UIColor.whiteColor()
        //添加视图
        addSubview(yuanQuan)
        addSubview(centerImg)
        addSubview(maakView)
        addSubview(textLabel)
        addSubview(registerButton)
        addSubview(loginButton)
        
        //设置布局, false 支持使用自动布局来设置控件位置

        for v in subviews{
            v.translatesAutoresizingMaskIntoConstraints = false
        }
        
        //圆圈
        addConstraint(NSLayoutConstraint(item: yuanQuan, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: yuanQuan, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1.0, constant: -80))
        
        //圆心图
        addConstraint(NSLayoutConstraint(item: centerImg, attribute: .CenterX, relatedBy: .Equal, toItem: yuanQuan, attribute: .CenterX, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: centerImg, attribute: .CenterY, relatedBy: .Equal, toItem: yuanQuan, attribute: .CenterY, multiplier: 1.0, constant: 0))
        
        //文字
        addConstraint(NSLayoutConstraint(item: textLabel, attribute: .CenterX, relatedBy: .Equal, toItem: yuanQuan, attribute: .CenterX, multiplier: 1.0, constant: 0));
        addConstraint(NSLayoutConstraint(item: textLabel, attribute: .Top, relatedBy: .Equal, toItem: yuanQuan, attribute: .Bottom, multiplier: 1.0, constant: 20))
        addConstraint(NSLayoutConstraint(item: textLabel, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 225));
        
        //注册按钮
        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .Left, relatedBy: .Equal, toItem: textLabel, attribute: .Left, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .Top, relatedBy: .Equal, toItem: textLabel, attribute: .Bottom, multiplier: 1.0, constant: 20))
        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 100))
        addConstraint(NSLayoutConstraint(item: registerButton, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 36))
        
        //登录按钮
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .Right, relatedBy: .Equal, toItem: textLabel, attribute: .Right, multiplier: 1.0, constant: 0))
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .Top, relatedBy: .Equal, toItem: textLabel, attribute: .Bottom, multiplier: 1.0, constant: 20))
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 100))
        addConstraint(NSLayoutConstraint(item: loginButton, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 36))
        
        //遮罩
        /**
        VFL : 可视化格式语言
        
        H 水平方向
        V 垂直方向
        | 边界
        [] 包装控件
        views: 是一个字典 [名字: 控件名] - VFL 字符串中表示控件的字符串
        metrics: 是一个字典 [名字: NSNumber] - VFL 字符串中表示某一个数值
        */

        addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[mask]-0-|", options: [], metrics: nil, views: ["mask": maakView]))
        addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[mask]-(btnHeight)-[regButton]", options: [], metrics: ["btnHeight": -36], views: ["mask": maakView, "regButton": registerButton]))
        
        // 设置背景颜色 - 灰度图 R = G = B，在 UI 元素中，大多数都使用灰度图，或者纯色图(安全色)
        backgroundColor = UIColor(white: 237.0 / 255.0, alpha: 1.0)

    }
        
}








